home *** CD-ROM | disk | FTP | other *** search
- const CLASS_ID = Components.ID("{C8938285-B9B3-4895-8209-26273DD745E9}");
- const CLASS_NAME = "Forecastfox Web Component";
- const CONTRACT_ID = "@ensolis.com/forecastfox/web;1";
- /******************************************************************************
- * ffWeb component
- ******************************************************************************/
- function ffWeb()
- {
- var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
- this._manager = Components.classes["@ensolis.com/forecastfox/manager;1"].getService(Components.interfaces.ffIManager);
- this._bundle = sbs.createBundle("chrome://forecastfox/locale/forecastfox.properties");
- this._prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
- };
-
- //version information
- ffWeb.prototype.version = "0.8.5";
-
- //install icon pack
- ffWeb.prototype.installIconPack = function (aName, aURL)
- {
- try {
- // make sure using HTTP or HTTPS and a jar file
- if (! /^https?:\/\/.+\.jar$/i.test(aURL))
- throw "Unsupported icon pack URL";
-
- } catch(e) {
- this._prompt.alert(null, this._bundle.GetStringFromName("ff.web.icons.label"),this._bundle.GetStringFromName("ff.web.icons.failed"));
- throw Components.results.NS_ERROR_INVALID_ARG;
- };
-
- //create parameters
- var array = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
- var name = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
- var url = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
- name.data = aName;
- url.data = aURL;
- array.AppendElement(name);
- array.AppendElement(url);
-
- //open install dialog
- var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher)
- ww.openWindow(this._manager.getWindow(), "chrome://forecastfox/content/icons.xul", "", "chrome,centerscreen,modal,dialog,titlebar", array);
- };
-
- ///////////////////////////
- // nsIClassInfo
- ffWeb.prototype.getInterfaces = function(aCount) {
- var ifaces = new Array();
- ifaces.push(Components.interfaces.ffIWeb);
- ifaces.push(Components.interfaces.nsIClassInfo);
- ifaces.push(Components.interfaces.nsISupports);
- aCount.value = ifaces.length;
- return ifaces;
- };
- ffWeb.prototype.getHelperForLanguage = function(aLanguage) {return null;}
- ffWeb.prototype.contractID = CONTRACT_ID;
- ffWeb.prototype.classID = CLASS_ID;
- ffWeb.classDescription = CLASS_NAME;
- ffWeb.prototype.flags = Components.interfaces.nsIClassInfo.DOM_OBJECT;
- ffWeb.implementationLanguage = Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT;
-
- ///////////////////////////
- // nsISupports
- ffWeb.prototype.QueryInterface = function (aIID) {
- if (!aIID.equals(Components.interfaces.ffIWeb) &&
- !aIID.equals(Components.interfaces.nsIClassInfo) &&
- !aIID.equals(Components.interfaces.nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- };
-
- /******************************************************************************
- * XPCOM Functions for construction and registration
- ******************************************************************************/
- var gModule = {
- _firstTime: true,
- registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
- {
- if (this._firstTime) {
- this._firstTime = false;
- throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
- };
- aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- aCompMgr.registerFactoryLocation(CLASS_ID, CLASS_NAME, CONTRACT_ID, aFileSpec, aLocation, aType);
-
- //register as global javascript property
- var catMgr = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
- catMgr.addCategoryEntry("JavaScript global property", "forecastfox", CONTRACT_ID, true, true);
- },
-
- unregisterSelf: function(aCompMgr, aLocation, aType)
- {
- aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);
-
- //unregister as global javascript property
- var catMgr = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
- catMgr.deleteCategoryEntry("JavaScript global property", "forecastfox", CONTRACT_ID, true);
- },
-
- getClassObject: function(aCompMgr, aCID, aIID)
- {
- if (!aIID.equals(Components.interfaces.nsIFactory))
- throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
-
- if (aCID.equals(CLASS_ID))
- return gFactory;
-
- throw Components.results.NS_ERROR_NO_INTERFACE;
- },
-
- canUnload: function(aCompMgr) { return true; }
- };
-
- var gFactory = {
- createInstance: function (aOuter, aIID)
- {
- if (aOuter != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- return (new ffWeb()).QueryInterface(aIID);
- }
- };
-
- function NSGetModule(aCompMgr, aFileSpec) { return gModule; }